<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico">
  <link rel="mask-icon" href="/images/favicon.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"daorongxing.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":true,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="1. 哈希表基本概念的入门哈希表也叫散列表，是通过key &amp; value来进行定位的数据结构，他把关键码值映射到表中一个位置来进行定位，这个映射函数叫做哈希函数；元素在数组位置position可以表示为hash(key)， 表面上只存放key，找到key就可以找到value。主要思想是空间换时间，可以节约遍历的时间成本，但是代价是需要建立字典库存储映射结果。  数组+链表结构数组查询方便，">
<meta property="og:type" content="article">
<meta property="og:title" content="3-hashtable">
<meta property="og:url" content="https://daorongxing.gitee.io/post/57281/index.html">
<meta property="og:site_name" content="邢道荣的个人博客">
<meta property="og:description" content="1. 哈希表基本概念的入门哈希表也叫散列表，是通过key &amp; value来进行定位的数据结构，他把关键码值映射到表中一个位置来进行定位，这个映射函数叫做哈希函数；元素在数组位置position可以表示为hash(key)， 表面上只存放key，找到key就可以找到value。主要思想是空间换时间，可以节约遍历的时间成本，但是代价是需要建立字典库存储映射结果。  数组+链表结构数组查询方便，">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://daorongxing.gitee.io/images/20190122151905332.png">
<meta property="article:published_time" content="2022-12-04T06:56:56.000Z">
<meta property="article:modified_time" content="2022-12-04T14:18:51.767Z">
<meta property="article:author" content="Daorong Xing">
<meta property="article:tag" content="算法">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://daorongxing.gitee.io/images/20190122151905332.png">

<link rel="canonical" href="https://daorongxing.gitee.io/post/57281/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>3-hashtable | 邢道荣的个人博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">邢道荣的个人博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://daorongxing.gitee.io/post/57281/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Daorong Xing">
      <meta itemprop="description" content="这是我的个人博客，记录计算机学习之路！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="邢道荣的个人博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          3-hashtable
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2022-12-04 14:56:56 / 修改时间：22:18:51" itemprop="dateCreated datePublished" datetime="2022-12-04T14:56:56+08:00">2022-12-04</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="1-哈希表基本概念的入门"><a href="#1-哈希表基本概念的入门" class="headerlink" title="1. 哈希表基本概念的入门"></a>1. 哈希表基本概念的入门</h1><p>哈希表也叫散列表，是通过<code>key &amp; value</code>来进行定位的数据结构，他把关键码值映射到表中一个位置来进行定位，这个映射函数叫做哈希函数；<br>元素在数组位置position可以表示为<code>hash(key)</code>， 表面上只存放key，找到key就可以找到value。<br>主要思想是空间换时间，可以节约遍历的时间成本，但是代价是需要建立字典库存储映射结果。</p>
<ul>
<li>数组+链表结构<br>数组查询方便，可以通过下标直接获得所对应的值，但是插入删除不方便，需要整体移动元素还需要扩容；<br>链表查询不方便，没有下标只能通过遍历的方式进行查询，增加插入方便，只需要找到需要插入的节点之后进行插入删除即可；<br>哈希表是两者的结合，获得了两者的优点。<br>哈希碰撞指经过哈希函数两个key都映射到了同一个数组位置上，那么这时候有两种解决方法。</li>
<li>拉链法：在同一个位置进行链表结构的扩充；</li>
<li>线性探索法： 往数组的下一个位置进行扩充；<br>需要考虑到的是<strong>查询效率</strong>，当链表长度过长，那么使用线性探索法；当链表长度足够，使用拉链法。<br>哈希攻击指的是黑客运用一些会转换为相同存储位置的数据注入，最后使得<strong>哈希表退化成一个单链表</strong>，降低了查询效率，DOS(Denial of Service, 拒绝服务供给)攻击.</li>
</ul>
<h2 id="1-1-hashMap"><a href="#1-1-hashMap" class="headerlink" title="1.1 hashMap"></a>1.1 hashMap</h2><h3 id="1-1-1-map基本操作"><a href="#1-1-1-map基本操作" class="headerlink" title="1.1.1 map基本操作"></a>1.1.1 map基本操作</h3><ul>
<li>hashMap的主要Api：<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">map.clear();</span><br><span class="line">map.size();</span><br><span class="line">map.isEmpty</span><br><span class="line">map.containsKey();判断</span><br><span class="line">map.containsValue();</span><br><span class="line">map.get(key);</span><br><span class="line">map.put(key,value);</span><br><span class="line">map.putAll(otherMap);</span><br><span class="line">map.remove(key);</span><br><span class="line">map.getOrDefault(key,defaultValue);查找key的值,不存在则返回默认值。</span><br><span class="line">map.entrySet();用来遍历每一对KV</span><br><span class="line"><span class="title function_">for</span><span class="params">(Map.Entry&lt;Integer，Integer&gt; etntey : map.entrySet()</span>)</span><br></pre></td></tr></table></figure></li>
<li>map遍历三种方式<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一种方式： keySet 取出map中所有键，封装为map集合</span></span><br><span class="line">		Set&lt;String&gt; s1=buy.keySet();</span><br><span class="line">		<span class="comment">//开始根据键找值</span></span><br><span class="line">		<span class="keyword">for</span> (String key : s1) &#123;</span><br><span class="line">			Integer value=buy.get(key);</span><br><span class="line">			System.out.println(key+<span class="string">&quot;-&gt;&gt;&gt;&gt;&quot;</span>+value);	</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 第二种方式： 将所有键值对取出封装为entrySet集合</span></span><br><span class="line">		Set&lt;Map.Entry&lt;String,Integer&gt;&gt; en=buy.entrySet();</span><br><span class="line">		<span class="keyword">for</span> (Map.Entry&lt;String, Integer&gt; entry : en) &#123;</span><br><span class="line">			String key=entry.getKey();</span><br><span class="line">			Integer value=entry.getValue();</span><br><span class="line">			System.out.println(key+<span class="string">&quot;-&gt;&gt;&gt;&quot;</span>+value);</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 第三种方式： Lambda表达式遍历</span></span><br><span class="line">		buy.forEach(<span class="keyword">new</span> <span class="title class_">BiConsumer</span>&lt;String, Integer&gt;() &#123;</span><br><span class="line">			<span class="meta">@Override</span></span><br><span class="line">			<span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">accept</span><span class="params">(String t, Integer u)</span> &#123;</span><br><span class="line">				System.out.println(t+<span class="string">&quot;-&gt;&gt;&gt;&quot;</span>+u);</span><br><span class="line">				</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;);</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="1-1-2-HashMap两个重要参数"><a href="#1-1-2-HashMap两个重要参数" class="headerlink" title="1.1.2 HashMap两个重要参数"></a>1.1.2 HashMap两个重要参数</h3><ul>
<li>初始容量大小：确定了哈希表底层数组的长度，必须是2的幂，默认初始值为16；</li>
<li>加载因子： 决定什么时候进行扩容，默认为0.75f，当数组存储元素个数超过<code>初始容量大小*加载因子</code>，数组就会用<code>refresh()</code>方法进行扩容，将数组扩大到原来的两倍。<br>扩容十分耗费性能，因为会生成一个新的数组，而且原来元素都要重新计算hashcode存入新的数组。</li>
</ul>
<h3 id="1-1-3-put方法原理"><a href="#1-1-3-put方法原理" class="headerlink" title="1.1.3 put方法原理"></a>1.1.3 put方法原理</h3><p>将key通过本地方法<code>public native int hashcode()</code>， 获取对应key的哈希码， 这个哈希码和key的存储位置有关，一般计算规则是取模存入，假如数组的长度是16个字节，key的hashcode是3214968，那么<code>3214968 mod 16 = 8</code>, 那么key就会被存储在数组的第8个位置，如果该位置为空则直接存入，如果该位置有值，就将插入的key与已经存在的key逐一进行equals判断，如果true就替换values，否则就以链表或红黑树(当链表长度大于8时)形式接入。此时<code>(key, value)</code>被封装为Node节点一同进行put操作</p>
<blockquote>
<p>红黑树是平衡二叉树，在查找的效率方面比链表高。</p>
</blockquote>
<ul>
<li>equals()和hashcode()关系<br>equals()方法对于基本数据类型，比较两个数的内容是否相等，而对于引用数据类型，则比较两个数的存储位置是否相等。<br>两个对象equals()了，那么他们的hashcode()一定相等；两个对象不equals()，他们的hashcode不一定不相等(经过算法可能计算出来相同的值，哈希碰撞的原理)<br>equals()重写了，hashcode()就一定要重写，否则可能两个对象equals，他们的hashcode仍然不相等，可能为后世使用埋下隐患;</li>
</ul>
<h3 id="1-1-4-get-key-方法原理"><a href="#1-1-4-get-key-方法原理" class="headerlink" title="1.1.4 get(key)方法原理"></a>1.1.4 get(key)方法原理</h3><p>首先调用hashcode()方法获取key的hashcode；<br>之后取模定位到数组的索引位置，如果位置为空，返回null；<br>如果有值，逐一遍历将key进行equal判断，成功则放回对应Node中的values；匹配不到返回null。</p>
<h3 id="1-1-5-hashMap-在Java1-7和1-8中的区别"><a href="#1-1-5-hashMap-在Java1-7和1-8中的区别" class="headerlink" title="1.1.5 hashMap 在Java1.7和1.8中的区别"></a>1.1.5 hashMap 在Java1.7和1.8中的区别</h3><h4 id="1-结构不同"><a href="#1-结构不同" class="headerlink" title="1. 结构不同"></a>1. 结构不同</h4><p>1.7采用的是数组+链表的数据结构<br>1.8采用的是数组+链表+红黑树的数据结构(当链表长度大于8时，扩展为红黑树)</p>
<h4 id="2-节点不同"><a href="#2-节点不同" class="headerlink" title="2. 节点不同"></a>2. 节点不同</h4><p>区别：<br>1.8中的hash作为一个常量，可以减少扩容时候再次计算哈希值造成的性能消耗。<br>1.8多了红黑树的节点。</p>
<h4 id="3-hash函数区别"><a href="#3-hash函数区别" class="headerlink" title="3. hash函数区别"></a>3. hash函数区别</h4><p>1.8相较于1.7只采用了一次位运算和一次与运算，而这次的目的是为了能够减少哈希碰撞，将高位和地位融合在一起，因为发现进行取模操作的时候对高位的影响是相对较小的。因为计算公式为<code>(n-1) &amp; hash</code>，对高位基本上是没有什么影响的。</p>
<blockquote>
<p>取模，hash%length，计算机中直接求余效率不如位移运算，源码中做了优化hash&amp;(length-1)，<code>hash % length == hash &amp; (length - 1)</code>的前提是length是2的n次方, 位运算特征，length是2的n次方，那么他减去1之后就是n个1，异或运算同0异1，这时候就能准确得出他在长度内的值是多少了。 </p>
</blockquote>
<h4 id="4-初始化方式"><a href="#4-初始化方式" class="headerlink" title="4. 初始化方式"></a>4. 初始化方式</h4><p>1.7：</p>
<ul>
<li>table是直接赋值给了一个空数组，在第一次put元素时初始化和计算容量。</li>
<li>table是单独定义的inflateTable（）初始化方法创建的。<br>1.8：</li>
<li>table没有赋值，属于懒加载，构造方式时已经计算好了新的容量位置（大于等于给定容量的最小2的次幂）。</li>
<li>table是resize（）方法创建的。</li>
</ul>
<h4 id="5-扩容方式"><a href="#5-扩容方式" class="headerlink" title="5. 扩容方式"></a>5. 扩容方式</h4><p>1.7： 运用异或对哈希值进行重新计算，运用resize()方法负责扩容，inflateTable()负责创建表；<br>1.8： 运用原来的哈希值加上扩容数组长度得到新的数组索引位置，节约了性能利用；表为空时候resize()创建表，表中有数值resize()扩容</p>
<h4 id="6-数据插入方式"><a href="#6-数据插入方式" class="headerlink" title="6. 数据插入方式"></a>6. 数据插入方式</h4><p>1.7： 头插法<br>1.8： 尾插法，避免了在并发时出现逆序和循环链表的情况</p>
<h3 id="1-1-6-线程问题"><a href="#1-1-6-线程问题" class="headerlink" title="1.1.6 线程问题"></a>1.1.6 线程问题</h3><p>1.7 死循环，数据丢失，并发执行扩容阶段<br>1.8 解决死循环，数据丢失仍然没有解决，并发put的时候</p>
<p>整体储存流程如下：<br><img src="/images/20190122151905332.png"></p>
<hr>
<h2 id="1-2-Set"><a href="#1-2-Set" class="headerlink" title="1.2 Set"></a>1.2 Set</h2><h3 id="1-2-1-Set集合基本操作"><a href="#1-2-1-Set集合基本操作" class="headerlink" title="1.2.1 Set集合基本操作"></a>1.2.1 Set集合基本操作</h3><p>list是有序的，元素可以重复的；set是无序的，不能重复的</p>
<ul>
<li>主要Api：<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">boolean</span> <span class="title function_">add</span><span class="params">(E object)</span> <span class="comment">//添加一个元素，添加成功返回true</span></span><br><span class="line"><span class="keyword">void</span> <span class="title function_">clear</span><span class="params">()</span> <span class="comment">//从Set集合中移除所有元素，该方法是从Collection集合继承过来的。</span></span><br><span class="line">Object <span class="title function_">clone</span><span class="params">()</span></span><br><span class="line"><span class="type">boolean</span> <span class="title function_">contains</span><span class="params">(Object object)</span> <span class="comment">//判断集合内是否包含元素</span></span><br><span class="line"><span class="type">boolean</span> <span class="title function_">isEmpty</span><span class="params">()</span> <span class="comment">//判断是否为空集合</span></span><br><span class="line">Iterator&lt;E&gt; <span class="title function_">iterator</span><span class="params">()</span> <span class="comment">//迭代器，遍历set集合用</span></span><br><span class="line"><span class="type">boolean</span> <span class="title function_">remove</span><span class="params">(Object object)</span> <span class="comment">//移除元素</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">size</span><span class="params">()</span> <span class="comment">//数组长度</span></span><br></pre></td></tr></table></figure></li>
<li>遍历方式</li>
</ul>
<ol>
<li>iterator遍历<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Set&lt;String&gt; set = <span class="keyword">new</span> <span class="title class_">HashSet</span>&lt;String&gt;();  </span><br><span class="line">Iterator&lt;String&gt; it = set.iterator();  </span><br><span class="line"><span class="keyword">while</span> (it.hasNext()) &#123;  </span><br><span class="line">  <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> it.next();  </span><br><span class="line">  System.out.println(str);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>增强for遍历<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (String str : set) &#123;  </span><br><span class="line">      System.out.println(str);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ol>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Daorong Xing
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://daorongxing.gitee.io/post/57281/" title="3-hashtable">https://daorongxing.gitee.io/post/57281/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/%E7%AE%97%E6%B3%95/" rel="tag"><i class="fa fa-tag"></i> 算法</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/post/24714/" rel="prev" title="类结构和类加载">
      <i class="fa fa-chevron-left"></i> 类结构和类加载
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-%E5%93%88%E5%B8%8C%E8%A1%A8%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E7%9A%84%E5%85%A5%E9%97%A8"><span class="nav-text">1. 哈希表基本概念的入门</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-hashMap"><span class="nav-text">1.1 hashMap</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-1-map%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="nav-text">1.1.1 map基本操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-2-HashMap%E4%B8%A4%E4%B8%AA%E9%87%8D%E8%A6%81%E5%8F%82%E6%95%B0"><span class="nav-text">1.1.2 HashMap两个重要参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-3-put%E6%96%B9%E6%B3%95%E5%8E%9F%E7%90%86"><span class="nav-text">1.1.3 put方法原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-4-get-key-%E6%96%B9%E6%B3%95%E5%8E%9F%E7%90%86"><span class="nav-text">1.1.4 get(key)方法原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-5-hashMap-%E5%9C%A8Java1-7%E5%92%8C1-8%E4%B8%AD%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-text">1.1.5 hashMap 在Java1.7和1.8中的区别</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-%E7%BB%93%E6%9E%84%E4%B8%8D%E5%90%8C"><span class="nav-text">1. 结构不同</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-%E8%8A%82%E7%82%B9%E4%B8%8D%E5%90%8C"><span class="nav-text">2. 节点不同</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-hash%E5%87%BD%E6%95%B0%E5%8C%BA%E5%88%AB"><span class="nav-text">3. hash函数区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E5%BC%8F"><span class="nav-text">4. 初始化方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-%E6%89%A9%E5%AE%B9%E6%96%B9%E5%BC%8F"><span class="nav-text">5. 扩容方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-%E6%95%B0%E6%8D%AE%E6%8F%92%E5%85%A5%E6%96%B9%E5%BC%8F"><span class="nav-text">6. 数据插入方式</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-6-%E7%BA%BF%E7%A8%8B%E9%97%AE%E9%A2%98"><span class="nav-text">1.1.6 线程问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-Set"><span class="nav-text">1.2 Set</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-1-Set%E9%9B%86%E5%90%88%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="nav-text">1.2.1 Set集合基本操作</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Daorong Xing"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">Daorong Xing</p>
  <div class="site-description" itemprop="description">这是我的个人博客，记录计算机学习之路！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">10</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="/2630168952@qq.com" title="E-Mail → 2630168952@qq.com"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="/2630168952@qq.com" title="QQ → 2630168952@qq.com"><i class="fa fa-qq fa-fw"></i></a>
      </span>
  </div>



<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
<div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div id="myCanvasContainer" class="widget tagcloud">
        <canvas width="250" height="250" id="resCanvas" style="width=100%">
            <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/JVM/" rel="tag">JVM</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Spring/" rel="tag">Spring</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%87%E9%92%88/" rel="tag">指针</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%AE%97%E6%B3%95/" rel="tag">算法</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%93%E6%9E%84%E4%BD%93/" rel="tag">结构体</a><span class="tag-list-count">1</span></li></ul>
        </canvas>
    </div>
</div>


      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Daorong Xing</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">91k</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
